<% layout('/layout/default.html', {title: '用户管理', libs: ['dataGrid','icheck']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-user"></i> 用户管理
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
				<a href="#" class="btn btn-default"  id="btnRefreshTree" title="刷新"><i class="fa fa-refresh"></i> 刷新</a>
				<% if(hasPermi('sys:user:edit')){ %>
					<a href="/sys/user/form" class="btn btn-default btnTool" title="新增用户"><i class="fa fa-plus"></i> 新增</a>
					<div class="btn-group">
						<a href="javascript:" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
							<i class="fa fa-navicon"></i> <span class="caret"></span>
						</a>
						<ul class="dropdown-menu">
							<li><a href="${ctx}/sys/user/export" id="btnExport"><i class="glyphicon glyphicon-export"></i> 导出</a></li>
							<li><a href="javascript:" id="btnImport"><i class="glyphicon glyphicon-import"></i> 导入</a></li>
						</ul>
					</div>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${user}" action="${ctx}/sys/user/listData" method="post" class="form-inline "
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">登录名：</label>
					<div class="control-inline">
						<#form:input path="loginName" maxlength="100" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">邮箱：</label>
					<div class="control-inline">
						<#form:input path="email" maxlength="300" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">手机：</label>
					<div class="control-inline">
						<#form:input path="mobile" maxlength="100" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">电话：</label>
					<div class="control-inline">
						<#form:input path="phone" maxlength="100" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-row"></div>
				<div class="form-group">
					<label class="control-label">用户名：</label>
					<div class="control-inline">
						<#form:input path="name" maxlength="100" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">公司：</label>
					<div class="control-inline width-90">
						<#form:treeselect id="company" name="company.id" title="公司选择"
								url="/sys/office/treeData?type=1" btnClass="btn-sm" allowClear="true" canSelectParent="true"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">机构：</label>
					<div class="control-inline width-90">
						<#form:treeselect  id="office" name="office.id" title="机构选择"
								 url="/sys/office/treeData?type=2" btnClass="btn-sm" allowClear="true" canSelectParent="true"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">状态：</label>
					<div class="control-inline width-90">
						<#form:select path="loginFlag" name="label" data="getDictList:sys_user_status"  blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">查询</button>
					<button type="button" class="btn btn-default btn-sm" onclick="resetForm()">重置</button>
				</div>
			</#form:form>
			<script type="text/javascript">
				function resetForm(){
					$(':input', '#searchForm')
					        .val('')
					        .removeAttr('checked')
					         .removeAttr('selected');
				}
			</script>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$('#btnImport').click(function(){
		js.layer.open({
			type: 1,
			area: ['400px'],
			title: '导入用户数据',
			resize: false,
			scrollbar: true,
			content: js.formatHtml('importTpl'),
			btn: ['<i class="fa fa-check"></i> 导入',
				'<i class="fa fa-remove"></i> 取消'],
            yes: function(index, layero){
				console.log(layero.find('#file').val());
				var form = {
					inputForm: layero.find('#inputForm'),
					file: layero.find('#file').val()
				};
			    if (form.file == '' || (!js.endWith(form.file, '.xls') && !js.endWith(form.file, '.xlsx'))){
			    	js.showMessage("文件不正确，请选择后缀为 “xls”或“xlsx”的文件。", null, 'warning');
			        return false;
			    }
				js.ajaxSubmitForm(form.inputForm, function(data){
					console.log(data);
					js.layer.closeAll();
					js.showMessage(data.message);
					page();
				});
				return true;
			},
            btn2: function(index, layero){
            }
		});
	});
</script>
<script id="importTpl" type="text">//<!--
<form id="inputForm" action="${ctx}/sys/user/import" method="post" enctype="multipart/form-data"
	class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
	<div class="row">
		<div class="col-xs-12 col-xs-offset-1">
			<input type="file" id="file" name="file" class="form-file"/>
			<div class="mt10 pt5">
				<a href="${ctx}/sys/user/import" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
			</div>
			<font color="red" class="pull-left mt10">
				提示：仅允许导入“xls”或“xlsx”格式文件！
			</font>
		</div>
	</div>
</form>
//--></script>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'登录名', name:'loginName', index:'a.loginName', width:200, align:"center"},
		{header:'用户名', name:'name', index:'a.name', width:200, align:"center"},
		{header:'归属公司', name:'company.name', index:'company.id', width:200, align:"center",sortable:false},
		{header:'归属机构', name:'office.name', index:'office.id', width:200, align:"center",sortable:false},
		{header:'电子邮箱', name:'email', index:'a.email', width:200, align:"center"},
		{header:'手机号码', name:'mobile', index:'a.mobile', width:200, align:"center"},
		{header:'办公电话', name:'phone', index:'a.phone', width:200, align:"center"},
		{header:'状态', name:'loginFlag', index:'a.login_flag', width:140, align:"center", formatter: function(val, obj, row, act){
			return js.transDictLabel(${@DictUtils.getDictListJson('sys_user_status')}, val, '未知');
		}},
		{header:'操作', name:'actions', width:200, sortable:false,align:"center", title:false, formatter: function(val, obj, row, act){
			var actions = [];
			var icon = row.loginFlag==1?'title="停用用户" data-confirm="确认要停用该用户吗?"><i class="fa fa-ban':'title="启用用户" data-confirm="确认要启该用户吗?"><i class="fa fa-check-square';
			<% if(hasPermi('sys:user:edit')){ %>
				actions.push('<a href="/sys/user/form?id='+row.id+'&op=edit" class="btnList" title="编辑用户"><i class="fa fa-pencil"></i></a>');
				actions.push('<a href="${ctx}/sys/user/changeStatus?id='+row.id+'&loginFlag='+row.loginFlag+'" class="btnList"'+icon+'"></i></a>');
				actions.push('<a href="${ctx}/sys/user/resetPass?id='+row.id+'&loginName='+row.loginName+'" class="btnList" title="重置密码" data-confirm="确认要重置为默认密码吗?"><i class="fa fa-reply-all"></i></a>');
				actions.push('<a href="${ctx}/sys/user/delete?id='+row.id+'" class="btnList" title="删除用户" data-confirm="确认要删除该用户吗?"><i class="fa fa-trash-o"></i></a>');
			<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>
